home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
macros
/
latex209
/
contrib
/
psfrag
/
ps2psfrag
/
ps2psfrag.ps
< prev
next >
Wrap
Text File
|
1992-09-19
|
5KB
|
165 lines
%! PS-Adobe-2.0
%
% PostScript program for reading a .ps file and writing out a LaTeX
% file that contains information about each piece of text shown by the
% ps file.
%
% GhostScript Usage:
%
% dx dy (fileName) FragConvert
%
% Reads fileName.ps and writes latex information to fileName.psfrag
% The show text coordinates are offset by dx, dy.
%
% Revision History:
% 20-Sep-92 Craig Barratt Released version 1.1.
% 13-Sep-92 Craig Barratt Added support for ashow, widthshow, awidthshow,
% and kshow.
% 21-Jul-92 Craig Barratt Correctly handle empty show strings. Added
% 9-Jun-92 Craig Barratt Changed egrep to grep for system V users.
% 1-Jun-92 Craig Barratt Released version 1.0.
% 23-Feb-92 Craig Barratt Initial version.
%
% Send comments and bugs to Craig Barratt (craig@isl.stanford.edu)
%
/fragdict 30 dict def
fragdict begin
% write a string to the output file
/w { FragOutFile exch writestring } bind def
% write an argument to the output file
/warg { ({) w w (}) w } bind def
/p { 16 string cvs print flush } def
/sp { ( ) p } def
%
% writes out latex information into the psfrag file for
% each show operator
%
/FragProcessShow {
FragPass 1 eq
{
% pass 1: write out just the show string
/s exch def
% we only care about non-empty show strings
s () eq not
{
s (\\tex) anchorsearch
{
pop pop
}
{
pop
( \\PsFragShowString) w s warg (\n) w
} ifelse
} if
}
{
% pass 2: write out psfrag info
/s exch def
% we only care about non-empty show strings
s () eq not
{
gsave
matrix currentmatrix /origMatrix exch def
currentpoint /origy exch def /origx exch def
% write out the string as the first arg
s (\\tex) anchorsearch {
% define this fragment using an empty label
pop ( \\psfrag{}) w w (\n) w
% now immediately refer to the empty label
( \\PsFragInfo{}) w
}
{
pop ( \\PsFragInfo) w s warg
} ifelse
% write out the current point in abs coords as the next two args
initmatrix currentpoint /abslly exch def /absllx exch def
absllx FragDx add 30 string cvs warg
abslly FragDy add 30 string cvs warg
% get width, height and orientation of the string
origMatrix setmatrix
newpath 0 0 moveto s true charpath pathbbox
/ury exch def /urx exch def pop pop
origx origy moveto urx 0 rmoveto
initmatrix currentpoint /abslry exch def /abslrx exch def
origMatrix setmatrix
origx origy moveto 0 ury rmoveto
initmatrix currentpoint /absuly exch def /absulx exch def
% write out dx and dy for the lower left to lower right vector
abslrx absllx sub 30 string cvs warg
abslry abslly sub 30 string cvs warg
% write out dx and dy for the lower left to upper left vector
absulx absllx sub 30 string cvs warg
absuly abslly sub 30 string cvs warg
% write out the text angle (keep it between -180 and 180,
% and round to the nearest 0.01)
abslry abslly sub abslrx absllx sub
% avoid atan(0,0): check if both numbers are zero
% (bug reported by Noel Doughty nad@phys.canterbury.ac.nz)
2 copy abs exch abs add
0 eq { pop pop 0 } { atan } ifelse
dup 360 div round 360 mul sub
100 mul round 100 div 30 string cvs warg
% finish up
(\n) w
origMatrix setmatrix
origx origy moveto
grestore
} if
} ifelse
} bind def
end
userdict begin
%
% redefine all the show operators to call FragProcessShow,
% and then do the normal show
%
/widthshow { dup fragdict begin FragProcessShow end widthshow } bind def
/awidthshow { dup fragdict begin FragProcessShow end awidthshow } bind def
/ashow { dup fragdict begin FragProcessShow end ashow } bind def
/kshow { dup fragdict begin FragProcessShow end kshow } bind def
/show { dup fragdict begin FragProcessShow end show } bind def
/FragConvert {
fragdict begin
/FragInFileName exch def
FragInFileName (frag) concatstrings (w) file /FragOutFile exch def
/FragDy exch def
/FragDx exch def
(\%\n\% File automatically generated by ps2psfrag and GhostScript.\n) w
(\% It is included by \\epsfbox or \\psfragspecial.\n) w
(\% Do not \\input directly, or edit!\n\%\n) w
(\\begin{PSFragmentLocs}\n) w
%
% I'm really lazy, so we run through the ps file twice.
% The first pass generates a list of \PsFragShowString{} calls.
% These are used by latex to check if the strings is being replaced.
% The second pass generates a list of \PsFragInfo{} calls, which
% contains complete information about each ps fragment.
%
/FragPass 1 def
gsave /FragVM save def
FragInFileName userdict begin run end
FragVM restore grestore
( \\put(0,0){\\special{\\PsFragSpecialArgs}}\n) w
/FragPass 2 def
gsave /FragVM save def
FragInFileName userdict begin run end
FragVM restore grestore
(\\end{PSFragmentLocs}\n) w
FragOutFile closefile
end
} bind def
end